//
//  FeedbackDetailsViewController.m
//  CoachsBook
//
//  Created by huiyong li on 2022/9/1.
//

#import "FeedbackDetailsViewController.h"
#import "TwoTabButView.h"
#import "FeedbackImageView.h"
#import "LongFeedbackImageCell.h"
#import "FeedbackDetailsCell.h"
#import "FeedbackDetailsModel.h"

@interface FeedbackDetailsViewController ()<UITableViewDelegate,UITableViewDataSource,TwoTabButViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
{
    FeedbackImageView *_FeedbackImageView;
}
@property (nonatomic, strong) NSMutableArray *imagedataArr;
@end

@implementation FeedbackDetailsViewController

- (NSMutableArray *)imagedataArr
{
    if (!_imagedataArr) {
        _imagedataArr = [NSMutableArray array];
    }
    return _imagedataArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navgationheadv.titlelabel.text = @"反馈详情";
    TwoTabButView *tabbutview = [[TwoTabButView alloc]initWithFrame:CGRectMake(0, APPheight-SafeAreaBottomHeight-65, APPwidth, 65)];
    tabbutview.delegate = self;
    [tabbutview.lefttabbut setTitle:@"结束进程" forState:UIControlStateNormal];
    [tabbutview.righttabbut setTitle:@"回复信息" forState:UIControlStateNormal];
    [self.view addSubview:tabbutview];
    
    [self getData];
}

- (void)setupUI {
    [super setupUI];
    self.tableView.frame = CGRectMake(0, SafeAreaTopHight, APPwidth, APPheight-SafeAreaTopHight-SafeAreaBottomHeight-65);
    
    
    
}

- (void)getData
{
    [self.imagedataArr removeAllObjects];
    [self.imagedataArr addObject:[UIImage imageNamed:@"camera_addicon"]];
    [self.imagedataArr addObject:[UIImage imageNamed:@"camera_addicon"]];
    [self.imagedataArr addObject:[UIImage imageNamed:@"camera_addicon"]];
    [self updateHeaderView];
    
    for (NSInteger i=0; i<10; i++) {
        FeedbackDetailsModel *model = [[FeedbackDetailsModel alloc]init];
        model.FeedbackType = i%2;
        model.FeedbackContent = @"风大顺丰到付打发大水发生范德萨发大水发嘎嘎嘎暗示法撒旦法大时光飞逝尬的双方各大沙发十多个阿凡达是范德萨范德萨发生的发多少是否都是发多少范德萨";
        if (i%3==0) {
            model.FeedbackContent = @"风大顺丰到付打发";
        }
        [self.dataArray addObject:model];
    }
    [self.tableView reloadData];
}

-(void)updateHeaderView{
    UIView *HeaderV = [[UIView alloc]initWithFrame:CGRectMake(0, 10, APPwidth, 45)];
    HeaderV.backgroundColor = [UIColor whiteColor];
    UIView *bjview = [[UIView alloc]initWithFrame:CGRectMake(16, 0, APPwidth-32, 145)];
    bjview.layer.cornerRadius = 10;
    bjview.layer.masksToBounds = YES;
    bjview.backgroundColor = rgba(235, 245, 253, 1);
    [HeaderV addSubview:bjview];
    
    
    UIImageView *iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(APPwidth-32-80, 0, 80, 70)];
    iconImage.image = CoachsBookImageName(@"已回复");
    [bjview addSubview:iconImage];
    
    
    NSString *ftitle = [NSString stringWithFormat:@"%@",@"近期使用感受"];
    NSString *ftype = [NSString stringWithFormat:@"%@",@"程序BUG"];
    NSString *fcontent = [NSString stringWithFormat:@"%@",@"最后在啰嗦一句，小编从来不会用个硬都撒割发代首功盖三分国时光飞逝的广告费施工方大使馆的施工方大公司的广东佛山割发代首。"];
    NSString *ftime = [NSString stringWithFormat:@"%@  %@",@"2022-08-23",@"10:21"];
    
    
    CGFloat titleLabelH = [LongHelper textHeight:ftitle WithUIFont:kPingFangRegular(16) AndWidth:APPwidth-32-170];
    titleLabelH = titleLabelH>20?titleLabelH:20;
    
    CGFloat typeLabelH = [LongHelper textHeight:ftype WithUIFont:kPingFangRegular(16) AndWidth:APPwidth-32-170];
    typeLabelH = typeLabelH>20?typeLabelH:20;
    
    CGFloat contentLabelH = [LongHelper textHeight:fcontent WithUIFont:kPingFangRegular(16) AndWidth:APPwidth-32-105];
    contentLabelH = contentLabelH>20?contentLabelH:20;
    
    
    UILabel *titleTLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 15, 75, 22)];
    titleTLabel.textColor = rgba(51, 51, 51, 1);
    titleTLabel.font = kPingFangRegular(16);
    titleTLabel.text = @"反馈标题:";
    [bjview addSubview:titleTLabel];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(90, 15, APPwidth-32-170, titleLabelH)];
    titleLabel.textColor = rgba(51, 51, 51, 1);
    titleLabel.font = kPingFangRegular(16);
    titleLabel.numberOfLines = 0;
    [bjview addSubview:titleLabel];
    
    
    UILabel *typeTLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(titleLabel.frame)+10, 75, 22)];
    typeTLabel.textColor = rgba(51, 51, 51, 1);
    typeTLabel.font = kPingFangRegular(16);
    typeTLabel.text = @"反馈类型:";
    [bjview addSubview:typeTLabel];
    
    UILabel *typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(90, CGRectGetMaxY(titleLabel.frame)+10, APPwidth-32-170, typeLabelH)];
    typeLabel.textColor = rgba(51, 51, 51, 1);
    typeLabel.font = kPingFangRegular(16);
    [bjview addSubview:typeLabel];
    
    
    UILabel *contentTLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(typeLabel.frame)+10, 75, 22)];
    contentTLabel.textColor = rgba(51, 51, 51, 1);
    contentTLabel.font = kPingFangRegular(16);
    contentTLabel.text = @"反馈内容:";
    [bjview addSubview:contentTLabel];
    
    UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(90, CGRectGetMaxY(typeLabel.frame)+10, APPwidth-32-105, contentLabelH)];
    contentLabel.textColor = rgba(51, 51, 51, 1);
    contentLabel.font = kPingFangRegular(16);
    contentLabel.numberOfLines = 0;
    [bjview addSubview:contentLabel];
    
    
    _FeedbackImageView = [[FeedbackImageView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(contentLabel.frame)+10, APPwidth, (APPwidth - 62)/3.0+20)];
    _FeedbackImageView.myCollectionView.delegate = self;
    _FeedbackImageView.myCollectionView.dataSource = self;
    _FeedbackImageView.backV.backgroundColor = rgba(235, 245, 253, 1);
    _FeedbackImageView.myCollectionView.backgroundColor = rgba(235, 245, 253, 1);
    [bjview addSubview:_FeedbackImageView];

    UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(_FeedbackImageView.frame)+10, APPwidth-32-30, 20)];
    timeLabel.textColor = rgba(153, 153, 153, 1);
    timeLabel.font = kPingFangRegular(14);
    [bjview addSubview:timeLabel];
    
    
    titleLabel.text = ftitle;
    typeLabel.text = ftype;
    contentLabel.text = fcontent;
    timeLabel.text = ftime;
    
    bjview.frame = CGRectMake(16, 0, APPwidth-32, CGRectGetMaxY(timeLabel.frame)+10);
    HeaderV.frame = CGRectMake(0, 10, APPwidth, CGRectGetMaxY(timeLabel.frame)+20);
    self.tableView.tableHeaderView = HeaderV;
}




#pragma mark - UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.imagedataArr.count;
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    LongFeedbackImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LongFeedbackImageCell" forIndexPath:indexPath];
    [cell cellFillWithImage:self.imagedataArr[indexPath.row]];
    cell.deleteBut.hidden = YES;
    return cell;
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    FeedbackDetailsModel *model = self.dataArray[indexPath.row];
    
    CGFloat contentLabelH = [LongHelper textHeight:model.FeedbackContent WithUIFont:kPingFangRegular(16) AndWidth:APPwidth-32-65-40];
    contentLabelH = contentLabelH>30?contentLabelH:30;
    return 34+contentLabelH;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FeedbackDetailsCell *cell=[tableView dequeueReusableCellWithIdentifier:@"FeedbackDetailsCell"];
    if (!cell) {
        cell=[[FeedbackDetailsCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"FeedbackDetailsCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row==0) {
        [cell cellFillWithModel:self.dataArray[indexPath.row] WithRow:0];
    }
    else if (indexPath.row == self.dataArray.count-1)
    {
        [cell cellFillWithModel:self.dataArray[indexPath.row] WithRow:2];
    }
    else{
        [cell cellFillWithModel:self.dataArray[indexPath.row] WithRow:1];
    }
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}


#pragma mark -TwoTabButViewDelegate
- (void)TwoTabButViewBtnSelectedDelegate:(NSInteger)tag
{
    if (tag == 0) {
        NSLog(@"结束进程");
    }
    else{
        
        NSLog(@"回复信息");

        
    }
}



@end
